<template>
	<div>
		<AplidForm ref="formRef" v-bind="BaseFormConfig" v-model="formModel" @submit="onSubmit"> </AplidForm>
	</div>
</template>

<script setup lang="ts">
import { BaseFormConfig } from '../../config'
import { getAreaObj } from '@/utils/util'
import { useCommonStore } from '@/stores/common'
const { setTempParams } = useCommonStore()

const emit = defineEmits(['submit'])

const rowData: any = inject('nowRowData')
const baseData = Object.freeze(JSON.parse(JSON.stringify(rowData.value)))
const formModel: any = ref({
	...rowData.value,
})
const formRef = ref(null)
const onSubmit = (form, done) => {
	const registerObj: any = getAreaObj(form.registerArea, 'register')
	const registerNameObj: any = getAreaObj(form.registerAreaNames, 'register')
	const areasObj: any = getAreaObj(form.areas)
	const areasNameObj: any = getAreaObj(form.areasName)
	const params = {
		...form,
		...areasObj,
		...areasNameObj,
		...registerObj,
		...registerNameObj,
		code: 3019,
	}
	const emptyObj = {
		registerArea: undefined,
		registerAreaNames: undefined,
		areas: undefined,
		areasName: undefined,
		code: undefined,
	}

	const changeObj = {
		data: [],
		dataChangeContentList: [
			{
				changeBefore: {
					...baseData,
					...emptyObj,
				},
				changeAfter: {
					...params,
					...emptyObj,
				},
				changeData: {
					...params,
					...emptyObj,
				},
				changeType: '养老行业服务商',
				code: 3019,
			},
		],
	}

	setTempParams({
		noChange: true,
		name: params.name,
		idCard: params.idCard,
		nowChange: changeObj,
	})
	emit('submit', changeObj)
	done()
}

const onSave = () => {
	formRef.value!.onSubmit()
}
defineExpose({
	onSave,
})
</script>

<style scoped></style>
